package com.example.dllo.exe.remen;

import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.example.dllo.exe.bean.ReMenBean;
import com.example.dllo.exe.R;
import com.example.dllo.exe.giftspeak.GiftSpeakSouSuoAty;
import com.example.dllo.exe.main.BaseFragment;
import com.example.dllo.exe.fengzhuang.NetTool;
import com.example.dllo.exe.fengzhuang.DBValue;

/**
 * code is far away from bug with the animal protecting
 * <p>
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃永无BUG！  凯哥 祝你一路顺风
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 */
public class ReMenFragment extends BaseFragment implements View.OnClickListener {

    private RecyclerView recyclerViewReMen;
    private ImageView imageViewsousuo;

    @Override
    protected int setLayout() {
        return R.layout.remenfragmentlayout;
    }

    @Override
    protected void initView() {
        recyclerViewReMen = bindView(R.id.ReMen_RV);
        imageViewsousuo = bindView(R.id.remmen_sousuoimage);
    }

    @Override
    protected void initData() {
        NetTool netTool = new NetTool();
        netTool.getNetData(DBValue.REMEN_REMEN, ReMenBean.class, new NetTool.NetListener<ReMenBean>() {
            @Override
            public void onSuccess(ReMenBean reMenBean) {
                GridLayoutManager manager = new GridLayoutManager(getContext(), 2);
                ReMenRvAdapter reMenRvAdapter = new ReMenRvAdapter(getContext());
                reMenRvAdapter.setReMenBean(reMenBean);
                recyclerViewReMen.setLayoutManager(manager);
                recyclerViewReMen.setAdapter(reMenRvAdapter);

                recyclerViewReMen.setHasFixedSize(true);
                reMenRvAdapter.setmOnItemClickListener(new ReMenRvAdapter.OnRecyclerViewItemClickListener() {
                    @Override
                    public void onItemClick(int position, ReMenBean reMenBean) {

                        Intent intent = new Intent(getContext(), ReMenSecondAty.class);
                        intent.putExtra("key", reMenBean.getData().getItems().get(position).getData().getUrl());
                        startActivity(intent);


//                        Toast.makeText(mContext, reMenBean.getData().getItems().get(position).getData().getUrl(), Toast.LENGTH_SHORT).show();
                    }
                });
            }


            @Override
            public void onError(String errorMsg) {

            }
        });
        imageViewsousuo.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
      switch (view.getId()){
          case R.id.remmen_sousuoimage:
              Intent intent=new Intent(getContext(), GiftSpeakSouSuoAty.class);
              startActivity(intent);
              break;
      }
    }
}
